<?php
/**
 * this class implement methods, which will be use to write configfiles
 * from an array 
 * @author snc
 *
 */
class ConfigHelper{
	/**
	 * constructor	 
	 */
	 function __construct(){
	 	
	 }
	 
	 /**
	  * write content of an array to ini file	  
	  * @param mixed $array
	  */
	 public static function writeINI($array,$fileName){
	 	//create file
	 	$configFile = APPLICATION_PATH."/configs/".$fileName;
	 	$fileHandle = fopen($configFile,"w") or die("can not create config file");	 	
	 	fclose($fileHandle);	 
	 	return file_put_contents($configFile,self::convertArrayToIniString($array));	
	 }
	 
	 /**
	  * convert an array to string to write to ini file
	  * Notice: this method is available for PHP <= 5.2	  
	  * @return String with ini structure
	  * @param unknown_type $array
	  */
	 public static function convertArrayToIniString($parents){
	 	$content = "";	 	
 		while(false !== ($parent = current($parents))){
 			//parent key
 			$content .= "[".key($parents)."]\n";
 			while(false !== ($children = current($parent))){
 				if(is_array($children)){
 					while(false !== ($child = current($children))){
 						$content .= key($parent)."[] = ".$child ."\n";
 						next($children);
 					}
 				}else{ 					
 					$content .= key($parent)." = ".$children ."\n";
 				}
 				next($parent);
 			}  			
 			next($parents);
 		}
	 	return $content;
	 }
	 
	 /**
	  * write content of an array to xml file	  
	  * @param mixed $array
	  */
	 public function writeXML($array){
	 	
	 }
}